package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.common.SimplePage;
import com.xinhe.web.entity.Member;
import com.xinhe.web.request.MemberModel;
import com.xinhe.web.request.MemberQuery;
import com.xinhe.web.response.MemberAccountDetailsView;
import com.xinhe.web.response.MemberComprehensiveAnalysisView;
import com.xinhe.web.response.MemberRecommendationDetailsView;
import com.xinhe.web.response.MemberView;
import com.xinhe.web.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Date;

@Api(value = "会员中心", tags = {"会员中心"})
@RestController
@RequestMapping(value = {"/member"}, produces = {"application/json;charset=UTF-8"})

public class MemberController {
    @Autowired
    private MemberService memberService;
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询会员")
    @RequestMapping(value = "/pageMember")
    public QueryResults<MemberView> query(@ApiParam(value = "手机号或者会员姓名") @RequestParam(required = false) String queryWord,
                                          @ApiParam(value = "实名状态") @RequestParam(name = "isCheckStatus",required = false) String isCheckStatus,
                                          int pageNum, int pageSize) {
        return memberService.pageMember(queryWord,isCheckStatus, pageNum,pageSize);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "导出会员列表记录")
    @RequestMapping({"/easyMemberExcel"})
    public void easyMemberExcel(HttpServletResponse response) {
        memberService.easyMemberExcel(response);
    }

    @WebUsed
    @ApiOperation("根据当前用户增加可提现余额，即：会员管理里面的增加金额")
    @PostMapping({"/addMemberBalance"})
    public Result addMemberBalance(Long userId, String tradeType, BigDecimal money, String remark) {
        return memberService.addMemberBalance(userId, tradeType, money, remark);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "后台额外赠送会员云茶籽")
    @PostMapping({"/sendSeedYunChaSeed"})
    public Result sendSeedYunChaSeed(Long userId, BigDecimal additionalYunChaSeed) {
        return memberService.sendSeedYunChaSeed(userId, additionalYunChaSeed);
    }

    @WebUsed
    @ApiOperation("后台设置军人标识")
    @RequestMapping({"/updateIdentifying"})
    public Result updateIdentifying(Long userId) {
        return memberService.updateIdentifying(userId);
    }
    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "设定角色")
    @PostMapping({"/updateMemberRole"})
    public Result updateMemberRole(Long userId, String role) {
        return memberService.updateMemberRole(userId, role);
    }
    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "设定角色2")
    @PostMapping({"/updateMemberRoleTwo"})
    public Result updateMemberRoleTwo(Long userId, String role) {
        return memberService.updateMemberRoleTwo(userId, role);
    }
    @WebUsed
    @ApiOperation("后台修改会员状态")
    @RequestMapping({"/updateMemberStatus"})
    public Result updateMemberStatus(Long userId, String status) {
        return memberService.updateMemberStatus(userId, status);
    }

    @WebUsed
    @ApiOperation("会员注册(平台)")//新增会员
    @RequestMapping({"/memberRegistration"})
    public Result memberRegistration(String name, String mobile, String parentCode) {
        return memberService.memberRegistration(name, mobile, parentCode);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "会员推荐奖励明细(平台)")
    @RequestMapping({"/pageMemberRecommendation"})
    public QueryResults<MemberRecommendationDetailsView> findByMemberRecommendation(String queryWord, Date startTime, Date endTime,
                                                                              int pageNum, int pageSize) {
        return memberService.findByMemberRecommendation(queryWord,startTime,endTime,pageNum,pageSize);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "导出会员推荐奖励记录")
    @RequestMapping({"/easyMemberRecommendationExcel"})
    public void easyMemberRecommendationExcel(String queryWord, Date startTime, Date endTime,
                                              int pageNum, int pageSize,HttpServletResponse response) {
        memberService.easyMemberRecommendationExcel(queryWord,startTime,endTime,pageNum,pageSize,response);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "会员账户明细(平台)，即会员账户总览")
    @RequestMapping({"/pageMemberAccountDetail"})
    public QueryResults<MemberAccountDetailsView> findByMemberAccountDetail(String queryWord, int pageNum, int pageSize) {
        return memberService.findByMemberAccountDetail(queryWord,pageNum,pageSize);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "综合分析，即综合统计")
    @RequestMapping({"/comprehensiveAnalysis"})
    public Result<MemberComprehensiveAnalysisView> comprehensiveAnalysis(Long serviceId , int pageNum, int pageSize) {
        return memberService.comprehensiveAnalysis(serviceId,pageNum,pageSize);
    }
    @WebUsed
    @ApiOperation("根据当前用户手机号查询统计结果(这个可以不做分页，下面给了不分页的查询)，即会员业绩统计明细")
    @PostMapping({"/findByMemberMobileStatistics"})
    public SimplePage findByMemberMobileStatistics(String mobile, Date startTime, Date endTime,
                                                   Integer pageNum, Integer pageSize) {
        return memberService.findByMemberMobileStatistics(mobile,startTime,endTime,pageNum,pageSize);
    }
    @ApiOperation("根据当前用户手机号查询统计结果(这个可以不做分页，下面给了不分页的查询)")
    @PostMapping({"/findByMemberMobileStatistics2"})
    public Result findByMemberMobileStatistics2(String mobile, Date startTime, Date endTime) {
        return memberService.findByMemberMobileStatistics2(mobile,startTime,endTime);
    }
    @WebUsed
    @ApiOperation("后台数量统计视图")
    @PostMapping({"/findByUserCount"})
    public Result findByUserCount() {
        return this.memberService.findByUserCount();
    }
    @WebUsed
    @ApiOperation("近30天后台数据统计图")
    @PostMapping({"/findByMoonDays"})
    public Result findByMoonDays() {
        return this.memberService.findByMoonDays();
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "市场会员消费排行榜top10(平台)")
    @RequestMapping({"/pageMemberConsumptionRanking"})
    public Result pageMemberConsumptionRanking(MemberQuery query) {
        return this.memberService.pageMemberConsumptionRanking(query);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "提现排行榜top10(平台)")
    @RequestMapping({"/pageMemberWithdrawal"})
    public Result pageMemberWithdrawal(MemberQuery query) {
        return this.memberService.pageMemberWithdrawal(query);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "创始人业绩排行榜TOP10(平台)")
    @RequestMapping({"/findByFounderConsumptionRanking"})
    public Result findByFounderConsumptionRanking(MemberQuery query) {
        return this.memberService.findByFounderConsumptionRanking(query);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "创始人提现排行榜TOP10(平台)")
    @RequestMapping({"/findByFounderWithdrawal"})
    public Result findByFounderWithdrawal(MemberQuery query) {
        return this.memberService.findByFounderWithdrawal(query);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "导出会员账户明细记录，即导出会员账户总览")
    @RequestMapping({"/easyMemberAccountDetailExcel"})
    public Result easyMemberAccountDetailExcel(MemberQuery query) {
        return this.memberService.easyMemberAccountDetailExcel(query);
    }
    @ApiOperation(httpMethod = "GET", value = "立即登录")
    @RequestMapping({"/memberLogInNow"})
    public Result memberLogInNow(String mobile, String password, String wxCode) {
        return this.memberService.memberLogInNow(mobile, password, wxCode);
    }
    @ApiOperation("我的资料")
    @RequestMapping(value = {"/findByMember"}, method = {RequestMethod.GET})
    public Result<MemberView> findByMember() {
        return this.memberService.findByMember();
    }
    @ApiOperation("获取手机号")
    @RequestMapping(value = {"/findByMemberPhone"}, method = {RequestMethod.GET})
    public Result<String> findByMemberPhone() {
        return this.memberService.findByMemberPhone();
    }
    @ApiOperation("获取直推数量和间推数量")
    @RequestMapping(value = {"/findByDirectPushAndInterpenetration"}, method = {RequestMethod.GET})
    public Result findByDirectPushAndInterpenetration() {
        return this.memberService.findByDirectPushAndInterpenetration();
    }
    @ApiOperation("获取直推成员(小程序)")
    @RequestMapping(value = {"/findByMemberDirectPush"}, method = {RequestMethod.GET})
    public Result findByMemberDirectPush() {
        return this.memberService.findByMemberDirectPush();
    }

    @ApiOperation("获取间推成员(小程序)")
    @RequestMapping(value = {"/findByMemberInterpenetration"}, method = {RequestMethod.GET})
    public Result findByMemberInterpenetration() {
        return this.memberService.findByMemberInterpenetration();
    }
    @ApiOperation(httpMethod = "GET", value = "获取不等于芯禾会员的用户")
    @RequestMapping({"/findByNotCommonMember"})
    public Result findByNotCommonMember(MemberQuery query) {
        return this.memberService.findByNotCommonMember(query);
    }

    @ApiOperation(httpMethod = "GET", value = "立即注册")
    @RequestMapping({"/memberRegisterNow"})//parentCode 邀请码
    public Result memberRegisterNow(String iconPath,String name,String mobile,String code,String wxCode,String parentCode) {
        return this.memberService.memberRegisterNow(iconPath, name, mobile, code, wxCode, parentCode);
    }

    @ApiOperation(httpMethod = "GET", value = "修改密码")
    @RequestMapping({"/updatePassword"})
    public Result updatePassword(String mobile,String code,String password,String confirmPassword) {
        return this.memberService.updatePassword(mobile, code, password, confirmPassword);
    }
    @ApiOperation("获取手机号")
    @RequestMapping({"/findByObtainMobile"})
    public Result<String> findByMobile(String code) {
        return this.memberService.findByMobile(code);
    }
    @ApiOperation("立即兑换茶油卡")
    @RequestMapping({"/redeemNowTeaOilCard"})
    public Result redeemNowTeaOilCard(Integer number) {
        return this.memberService.redeemNowTeaOilCard(number);
    }
    @ApiOperation("我的资产")
    @RequestMapping(value = {"/findByMemberAssetCount"}, method = {RequestMethod.GET})
    public Result findByMemberAssetCount() {
        return this.memberService.findByMemberAssetCount();
    }

    @ApiOperation(httpMethod = "POST", value = "绑定服务中心")
    @PostMapping({"/updateBandingService"})
    public Result updateBandingService(Long userId, Long serviceCenterId) {
        return this.memberService.updateBandingService(userId, serviceCenterId);
    }
    @ApiOperation(httpMethod = "POST", value = "取消绑定服务中心")
    @PostMapping({"/updateCancelBanding"})
    public Result updateCancelBanding(Long userId) {
        return this.memberService.updateCancelBanding(userId);
    }

    @ApiOperation("修改会员手机号")
    @GetMapping({"/updateMemberMobile"})
    public Result updateMemberMobile(Long userId, @RequestParam("mobile") String mobile) {
        return this.memberService.updateMemberMobile(userId, mobile);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询会员")
    @RequestMapping({"/pageMemberApp"})
    public QueryResults<MemberView> pageMemberApp(@RequestBody MemberQuery query) {
        return this.memberService.pageMember(query.getKeyword(),String.valueOf(query.getIsCheckStatus()),query.getPageNum(),query.getPageSize());
    }

   @ApiOperation(httpMethod = "POST", value = "保存会员")
    @RequestMapping({"/saveMember"})
    public Result saveMember(@Valid MemberModel model) {
        return this.memberService.saveMember(model);
    }
    @ApiOperation(httpMethod = "GET", value = "删除会员")
    @ApiImplicitParam(name = "memberId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteMember"})
    public Result deleteMember(Long memberId) {
        return this.memberService.delete(memberId);
    }
    @ApiOperation(httpMethod = "GET", value = "会员详情")
    @ApiImplicitParam(name = "memberId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailMember"})
    public Result<Member> detailMember(Long memberId) {
        return this.memberService.findById(memberId);
    }
    @ApiOperation("我的团队统计数据")
    @PostMapping({"/findByMemberTeam"})
    public Result findByMemberTeam() {
        return this.memberService.findByMemberTeam();
    }
    @ApiOperation("数据统计（家园天使、创始人、智慧合伙人本人）")
    @PostMapping({"/findByFounderStatistics"})
    public Result findByFounderStatistics() {
        return this.memberService.findByFounderStatistics();
    }
    @ApiOperation("服务中心统计中心数据")
    @PostMapping({"/findByServiceStatistics"})
    public Result findByServiceStatistics() {
        return this.memberService.findByServiceStatistics();
    }
    @ApiOperation("公司统计中心数据")
    @PostMapping({"/findByCompanyStatistics"})
    public Result findByCompanyStatistics() {
        return this.memberService.findByCompanyStatistics();
    }
    @ApiOperation("周统计图(家园天使、创始人、智慧合伙人)")
    @PostMapping({"/findByStatisticalChart"})
    public Result findByStatisticalChart() {
        return this.memberService.findByStatisticalChart();
    }
    @ApiOperation("服务中心周统计图")
    @PostMapping({"/findByServiceStatisticalChart"})
    public Result findByServiceStatisticalChart() {
        return this.memberService.findByServiceStatisticalChart();
    }
    @ApiOperation("公司周统计图")
    @PostMapping({"/findByCompanyStatisticalChart"})
    public Result findByCompanyStatisticalChart() {
        return this.memberService.findByCompanyStatisticalChart();
    }

    /*
    @ApiOperation(httpMethod = "GET", value = "导出认养订单记录")
    @RequestMapping({"/easyAdoptedOrderExcel"})
    public Result<String> easyAdoptedOrderExcel(AdoptedTreeOrderQuery query) {
        return this.memberService.easyAdoptedOrderExcel(query);
    }
    @ApiOperation(httpMethod = "GET", value = "导出资产流水记录")
    @RequestMapping({"/easyAssetFlowExcel"})
    public Result<String> easyAssetFlowExcel(AssetDetailByBackManagerQuery query) {
        return this.memberService.easyAssetFlowExcel(query);
    }

    @ApiOperation(httpMethod = "GET", value = "导出实名认证记录")
    @RequestMapping({"/easyIdentityExcel"})
    public Result<String> easyIdentityExcel(IdentityQuery query) {
        return this.memberService.easyIdentityExcel(query);
    }
    @ApiOperation(httpMethod = "GET", value = "导入会员信息")
    @RequestMapping({"/importMembers"})
    public Result importMembers(MultipartFile file) {
        return this.memberService.importMembers(file);
    }
    @ApiOperation(httpMethod = "GET", value = "导入会员直推和间推")
    @RequestMapping({"/importMembersTwoAndThree"})
    public Result importMembersTwoAndThree(MultipartFile file) {
        return this.memberService.importMembersTwoAndThree(file);
    }
    @ApiOperation(httpMethod = "GET", value = "导入会员提现信息")
    @RequestMapping({"/importMembersWithdrawals"})
    public Result importMembersWithdrawals(MultipartFile file) {
        return this.memberService.importMembersWithdrawals(file);
    }
    @ApiOperation(httpMethod = "GET", value = "导入会员认养记录信息")
    @RequestMapping({"/importMembersAdoptedOrder"})
    public Result importMembersAdoptedOrder(MultipartFile file) {
        return this.memberService.importMembersAdoptedOrder(file);
    }
    @ApiOperation(httpMethod = "GET", value = "导入云茶籽解冻信息")
    @RequestMapping({"/importMembersYunChaSeed"})
    public Result importMembersYunChaSeed(MultipartFile file) {
        return this.memberService.importMembersYunChaSeed(file);
    }
    @ApiOperation(httpMethod = "GET", value = "导入消费金红包解冻信息")
    @RequestMapping({"/importMembersConsumerGoldRedEnvelope"})
    public Result importMembersConsumerGoldRedEnvelope(MultipartFile file) {
        return this.memberService.importMembersConsumerGoldRedEnvelope(file);
    }
    @ApiOperation(httpMethod = "GET", value = "导入茶油卡兑换记录信息")
    @RequestMapping({"/importMembersTeaOilCardRecord"})
    public Result importMembersTeaOilCardRecord(MultipartFile file) {
        return this.memberService.importMembersTeaOilCardRecord(file);
    }
   */
}
